<script type="text/javascript">
    {literal}
        $(document).ready(function() {
            $("#fulltext").keyup(function(event){
                if(event.keyCode == 13){
                    setFulltext($('#fulltext').val(),'list_of_clients_fulltext')
                }
            });
            $("#fulltext").focus();
        });
    {/literal}
</script>

<ul class="subNavig">
    <li><a href="{$data.root}?input=list_of_clients">Clients</a></li>
    <li><a href="{$data.root}?input=list_of_users">Users</a></li>
    <li><a href="{$data.root}?input=list_of_tariffs">Tariffs</a></li>
    <li><a href="{$data.root}?input=fixed_expense">Fixed expenses</a></li>
</ul>
<h2 class="pageTitle">List of clients</h2>
{include $data.pathToError}
{if $data.currentFilter || $data.currentFulltext!=''}
    <div class="menu-list bgDark">
        <b>Current filter:</b> 
        <ul>
            {foreach $data.currentFilter as $filter => $value}
                <li>{$filter} = <i>{$value}</i> [<a href="javascript: cancelFilter('{$filter}','list_of_clients_filter')" class="baseLink">Cancel</a>]</li>
            {/foreach}
            {if $data.currentFulltext != ''}
                <li>Fulltext = <i>{$data.currentFulltext}</i> [<a href="javascript: cancelFulltext('list_of_clients_fulltext')" class="baseLink">Cancel</a>]</li>
            {/if}
        </ul>
    </div>
{/if}
<div class="menu-list">
    Fulltext search: <input id="fulltext" type="text" value="{if $data.currentFulltext != ''}{$data.currentFulltext}{/if}" /><input value="Search" type="button" onclick="setFulltext($('#fulltext').val(),'list_of_clients_fulltext')" />
</div>
<form action="{$data.root}?input=list_of_clients" method="post" id="addingClient">
    <div class="menu-list">
        <a href="{$data.root}?input=add_client" class="basicButton">Add client</a>
        <select name="action" onchange="submitForm('addingClient')">
            <option value="">Actions ...</option>
            <option value="deleteClients">Delete client(s)</option>
        </select>
    </div>
    <table class="list">
        <tr>
            <th><input type="checkbox" id="checkAll" onchange="checkIt('checkAll')" /></th>
            <th><a href="javascript: order('name','list_of_clients_order')">Name {if $data.currentOrder.0=="name"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
            <th><a href="javascript: order('fullName','list_of_clients_order')">Full name {if $data.currentOrder.0=="fullName"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
            <th><a href="javascript: order('ICO','list_of_clients_order')">ICO {if $data.currentOrder.0=="ICO"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
            <th><a href="javascript: order('ICDPH','list_of_clients_order')">ICDPH {if $data.currentOrder.0=="ICDPH"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
            <th><a href="javascript: order('address','list_of_clients_order')">Address {if $data.currentOrder.0=="address"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
            <th><a href="javascript: order('city','list_of_clients_order')">City {if $data.currentOrder.0=="city"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
            <th><a href="javascript: order('zip','list_of_clients_order')">ZIP {if $data.currentOrder.0=="zip"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
            <th><a href="javascript: order('typeOfCooperation','list_of_clients_order')">Type of cooperation {if $data.currentOrder.0=="typeOfCooperation"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
            <th><a href="javascript: order('monthlyFee','list_of_clients_order')">Monthly fee {if $data.currentOrder.0=="monthlyFee"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
            <th><a href="javascript: order('monthlyPrepaid','list_of_clients_order')">Prepaid monthly range {if $data.currentOrder.0=="monthlyPrepaid"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
            <th><a href="javascript: order('contactPerson','list_of_clients_order')">Contact person {if $data.currentOrder.0=="contactPerson"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
            <th><a href="javascript: order('active','list_of_clients_order')">Active {if $data.currentOrder.0=="active"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
            <th><a href="javascript: order('bad_payer','list_of_clients_order')">Bad payer {if $data.currentOrder.0=="bad_payer"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
            <th><a href="javascript: order('domain','list_of_clients_order')">Domain {if $data.currentOrder.0=="domain"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
        </tr>
        {assign var=counter value=1}
        {foreach $data.clients as $key => $client}
            {if $counter==1}
                {assign var=bgClass value='bgDark'}
            {else}
                {assign var=bgClass value='bgLight'}
            {/if}
            <tr class="{$bgClass}">
                {if $counter==1}
                    {assign var=counter value=2}
                {else}
                    {assign var=counter value=1}
                {/if}
                <td>
                    <input name="clientId[]" value="{$client.klient_id}" class="clientSelector" type="checkbox" />
                </td>
                <td style="width: 5em"><a class="filterLink" href="{$data.root}?input=edit_client&client={$client.klient_id}">{$client.name}</a></td>
                <td style="width: 7em">{$client.fullName}</td>
                <td class="center">{$client.ICO}</td>
                <td class="center">{$client.ICDPH}</td>
                <td style="width: 6em" class="center">{$client.address}</td>
                <td class="center"><a class="filterLink" href="javascript: filter('city','{$client.city}','list_of_clients_filter')">{$client.city}</a></td>
                <td class="center"><a class="filterLink" href="javascript: filter('zip','{$client.zip}','list_of_clients_filter')">{$client.zip}</a></td>
                <td style="width: 6em" class="center"><a class="filterLink" href="javascript: filter('typeOfCooperation','{$client.typeOfCooperation}','list_of_clients_filter')">{$client.cooperation_info.type}</a></td>
                <td style="width: 4em" class="center">{$client.monthlyFee}</td>
                <td style="width: 4em" class="center">{$client.monthlyPrepaid}</td>
                <td style="width: 4em" class="center">
                    {if $client.contact_person_info}
                        <a class="filterLink" href="javascript: filter('contactPerson','{$client.contactPerson}','list_of_clients_filter')">{$client.contact_person_info.name} {$client.contact_person_info.surname}</a>
                    {/if}                
                </td>
                <td class="center">
                    <a class="filterLink" href="javascript: filter('active','{$client.active}','list_of_clients_filter')">
                        {if $client.active == 0}
                            Yes
                        {else}
                            No
                        {/if}
                    </a>
                </td>
                <td class="center">
                    <a class="filterLink" href="javascript: filter('bad_payer','{$client.bad_payer}','list_of_clients_filter')">
                        {if $client.bad_payer == 1}
                            Yes
                        {else}
                            No
                        {/if}
                    </a>
                </td>
                <td class="center">{$client.domain}</td>
            </tr>
        {/foreach}
        <tr>
            <td colspan="9" style="text-align: right">Sum of monthly fee on this page is </td>
            <td class="center"><b>{$data.pageSum|round:"2"}</b></td>
            <td colspan="5" style="text-align: left">from total sum <b>{$data.totalSum|round:"2"}</b></td>
        </tr>
    </table>
</form>
<div class="menu-list">
    <span class="pager">{$data.pager}</span>
    Records per page
    <select class="pager" size="1" onchange="changeRecordsPerPage(this.value, 'list_of_clients_pager')">
        <option {if $smarty.session.list_of_clients_pager==20}selected="selected"{/if} value="20">20</option>
        <option {if $smarty.session.list_of_clients_pager==50}selected="selected"{/if} value="50">50</option>
        <option {if $smarty.session.list_of_clients_pager==100}selected="selected"{/if} value="100">100</option>
    </select>
    Count: {$data.total_count}
</div>